home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / bit / src / mpeg / gldisplay.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  153 lines

  1. /********************************************************************
  2.  *. This file is part of BIT shareware package.
  3.  *
  4.  *  Copyright(c) 1993, 1994 by T.C. Zhao.
  5.  *  All rights reserved.
  6.  *.
  7.  *
  8.  *******************************************************************/
  9.  
  10. #include "video.h"
  11. #include "gl/gl.h"
  12. #include "gl/device.h"
  13.  
  14. static long winh = 290, winw = 330;
  15. static long winid = -1;
  16. static float zoom = 2.0;
  17. static int w, h;
  18.  
  19. extern int noDisplayFlag;
  20. extern int run_in_background;
  21.  
  22. void
  23. set_maginification(float f)
  24. {
  25.     zoom = f;
  26. }
  27.  
  28. static void
  29. resize_win(void)
  30. {
  31.     long xo, yo;
  32.  
  33.     winset(winid);
  34.     getorigin(&xo, &yo);
  35.     winw = w * zoom;
  36.     winh = h * zoom;
  37.     winposition(xo, xo + winw - 1, yo, yo + winh - 1);
  38. }
  39.  
  40. static void
  41. remap_win(void)
  42. {
  43.     winset(winid);
  44.     reshapeviewport();
  45.     getsize(&winw, &winh);
  46.     cpack(0);
  47.     clear();
  48.     reshapeviewport();
  49.     ortho2(-0.5, winw - 0.5, -0.5, winh - 0.5);
  50. }
  51.  
  52. static void
  53. finish_it(void)
  54. {
  55.     winclose(winid);
  56.     gexit();
  57.     exit(1);
  58. }
  59.  
  60. static void
  61. check_events(void)
  62. {
  63.     long dev;
  64.     short val;
  65.     static char *spop = "MPEGcntl%t|1x1|2x2|3x3|Quit %x10";
  66.     static long menu = -1;
  67.     int p;
  68.  
  69.     if (!qtest())
  70.     return;
  71.  
  72.     if (menu < 0)
  73.     menu = defpup(spop);
  74.  
  75.     switch ((dev = qread(&val)))
  76.       {
  77.       case MENUBUTTON:
  78.       if (val)
  79.         {
  80.         switch ((p = dopup(menu)))
  81.           {
  82.           case 1:
  83.           case 2:
  84.           case 3:
  85.               zoom = p;
  86.               resize_win();
  87.               remap_win();
  88.               rectzoom((float) p, (float) p);
  89.               break;
  90.           case 10:
  91.               finish_it();
  92.               break;
  93.           }
  94.         }
  95.       break;
  96.       case REDRAW:
  97.       if (val == winid)
  98.           remap_win();
  99.       break;
  100.       case ESCKEY:
  101.       if (val)
  102.           finish_it();
  103.       case SPACEKEY:
  104.       if (val)
  105.         {
  106.         while (qread(&val) != SPACEKEY || !val)
  107.             ;
  108.         }
  109.       break;
  110.       }
  111. }
  112.  
  113. void
  114. glDisplay(VidStream * vid_stream)
  115. {
  116.  
  117.     int x, y;
  118.  
  119.     if (noDisplayFlag)
  120.     return;
  121.  
  122.     w = vid_stream->mb_width * 16;
  123.     h = vid_stream->mb_height * 16;
  124.  
  125.     if (winid <= 0)
  126.       {
  127.       winw = zoom * w;
  128.       winh = zoom * h;
  129.       if (!run_in_background)
  130.           foreground();
  131.       prefsize(winw, winh);
  132.       winid = winopen("BIT: sgimpeg");
  133.       RGBmode();
  134.       gconfig();
  135.       remap_win();
  136.       rectzoom(zoom, zoom);
  137.       qdevice(ESCKEY);
  138.       qdevice(SPACEKEY);
  139.       qdevice(MENUBUTTON);
  140.       }
  141.  
  142.     check_events();
  143.  
  144.     /* center the image both horizontally and vertically in window */
  145.  
  146.  
  147.     x = (winw - w * zoom) / 2;
  148.     y = (winh - h * zoom) / 2;
  149.  
  150.     lrectwrite(x, y, w + x - 1, h + y - 1,
  151.            (unsigned long *) vid_stream->current->display);
  152. }
  153.